#include "scenariotest.h"

/*Registry this TestSuite to theTestFactoryRegistry*/
CPPUNIT_TEST_SUITE_REGISTRATION (ScenarioTest);

void ScenarioTest::setUp() {
	SG_init();
}

void ScenarioTest::testConstructorDestructor() { fprintf(stderr,">>> ScenarioTest::testConstructorDestructor()\n");
	Grid *g = new Grid("grid1");
	Job *j = new Job("job1", 100, 1);
	/*Create a scenario*/
	Scenario *scene = new Scenario("scene1", j, g);
	
	/*Delete a the scenario*/
	delete scene;
}

void ScenarioTest::testWriteToXML() { fprintf(stderr,">>> ScenarioTest::testWriteToXML()\n");
	/*Creating the grid*/
	Grid *g = new Grid("grid1");
	g->addSite("site1","../data/traces/linkbw1Mbit",0, NULL, 0, NULL, 0,NULL, 0, "../data/traces/linkbw1Mbit", "../data/traces/cpuerror.0", "../data/traces/cpuerror.0");
//	g->getSiteByDomain("site1")->addProcessor(1,"../data/traces/cputrace.0",10);
//	g->getSiteByDomain("site1")->addProcessor(1,"../data/traces/cputrace.0",50);	
//	g->getSiteByDomain("site1")->addProcessor(2,"../data/traces/cputrace.0",10);	

	g->addSite("site2","../data/traces/linkbw1Mbit",0, "../data/traces/cputrace.0", 0, "../data/traces/linkbw1Mbit", 0,"../data/traces/linkbw1Mbit", 0, "../data/traces/cpuerror.0", "../data/traces/cpuerror.0", "../data/traces/cpuerror.0");
	g->getSiteByDomain("site2")->addProcessor(3,"../data/traces/cputrace.0",0, "../data/traces/cpuerror.0");
	g->getSiteByDomain("site2")->addProcessor(4,"../data/traces/cputrace.0",0, "../data/traces/cpuerror.0");
	g->getSiteByDomain("site2")->addProcessor(1,"../data/traces/cputrace.0",0, "../data/traces/cpuerror.0");

	g->addSite("site3","../data/traces/linkbw1Mbit",0, "../data/traces/cputrace.0", 0, "../data/traces/linkbw1Mbit", 0,"../data/traces/linkbw1Mbit", 0, "../data/traces/cpuerror.0", "../data/traces/cpuerror.0", "../data/traces/cpuerror.0");
	g->getSiteByDomain("site3")->addProcessor(3,"../data/traces/cputrace.0",0, "../data/traces/cpuerror.0");
	g->getSiteByDomain("site3")->addProcessor(7,"../data/traces/cputrace.0",0, "../data/traces/cpuerror.0");
	g->getSiteByDomain("site3")->addProcessor(2,"../data/traces/cputrace.0",0, "../data/traces/cpuerror.0");

	/*Creating the Job*/
	Job *j = new Job("job1", 100, 1);
	j->addTask(500,0);
	j->addTask(600,0);	
	j->addTask(700,0);	
	j->addTask(200,0);
	j->addTask(400,0);	
	j->addTask(300,0);	
	j->addTask(800,0);
	j->addTask(1000,0);	
	j->addTask(1050,0);	
	j->addTask(780,0);

	/*Create a scenario*/
	Scenario *scene = new Scenario("scene1", j, g, 2, 0.214);

	scene->setJobInputSize(1000);
	scene->setAverageTaskInputSize(10);
	scene->setAverageTaskOutputSize(10);
	scene->setInputHeterogeneity(10);
	scene->setOutputHeterogeneity(10);
	scene->setGridSpeed(10);
	scene->setGridHeterogeneity(10);

	
	CPPUNIT_ASSERT_EQUAL(scene->getNumberOfExecutions(), 2);
	
	scene->writeToXML("../data/unittest.xml");
	
}

void ScenarioTest::tearDown() {
	SG_clear();
}
